package main

import "fmt"

func main() {
	// s := [][]int{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
	// s := [][]int{{1, 2, 3, 4}}
	s := [][]int{{1}, {2}, {3}, {4}}
	Matrix(s)
}

func Matrix(s [][]int) {
	if s == nil {
		fmt.Println("slice is nil")
	}
	x, y := 0, 0
	h := len(s) - 1
	l := len(s[0]) - 1
	if h == 0 {
		for _, v := range s[0] {
			fmt.Println(v)
		}
		return
	}

	if l == 0 {
		for _, v := range s {
			fmt.Println(v[0])
		}
		return
	}

	for x <= h && y <= l {
		ax, ay := x, y
		for ay < l {
			fmt.Println(s[ax][ay])
			ay++
		}
		for ax < h {
			fmt.Println(s[ax][ay])
			ax++
		}
		for ay > y {
			fmt.Println(s[ax][ay])
			ay--
		}
		for ax > x {
			fmt.Println(s[ax][ay])
			ax--
		}
		x++
		y++
		h--
		l--
	}
}
